﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using System.Data.SqlClient;

namespace SIPO.Library.DataAccess.Report
{
    public class rptInvoiceRepo
    {
        private string connectionString;

        public rptInvoiceRepo(string ConnectionString)
        {
            connectionString = ConnectionString;
        }

        public DataTable GetInvoice(string invoiceNo, string action)
        {
            DataTable dt = new DataTable();

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    if (action == "registrasi")
                        cmd.CommandText = "[dbo].[Sp_Rpt_InvoiceRegistration]";
                    else
                        cmd.CommandText = "[dbo].[Sp_Rpt_InvoiceCorporateAction]";

                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@invoiceNo", SqlDbType.VarChar).Value = invoiceNo;

                    SqlDataAdapter da = new SqlDataAdapter();
                    da.SelectCommand = cmd;

                    try
                    {
                        conn.Open();
                        da.Fill(dt);
                    }
                    catch (Exception ex)
                    {
                        throw (ex);
                    }
                    finally
                    {
                        if (conn.State == ConnectionState.Open) conn.Close();
                    }

                }
            }

            return dt;

        }

    }
}
